package Util;

import java.io.File;
import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;
import org.xml.sax.SAXException;

public class XmlUtil {

	public static Document getDocument() throws ParserConfigurationException, SAXException, IOException{
	DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
	DocumentBuilder builder=factory.newDocumentBuilder();
		return builder.parse(new File("src/Student.xml"));
		
	}

	public static void write2Xml(Document document) throws TransformerException{
		TransformerFactory factory=TransformerFactory.newInstance();
		Transformer tf=factory.newTransformer();
		tf.transform(new DOMSource(document), new StreamResult(new File("src/Student.xml")));
		
	}
}
